<template>
	<view class="content" :style="{'padding-top':top+'px','min-height':windowheight+'px'}">
		<Nav title1="我的" bgColor="#da708b" :backIcon="false" style="color: #ffffff;z-index: 1;" id="nav"></Nav>
		<view class="myinfo">
			<view class="myinfo_avator">
				<image :src="my_avatarurl" style="width: 100%;height: 100%;border-radius: 50%;"></image>
			</view>
			<!-- <view class="myinfo_nickname">{{my_nickname}}  #{{client_no}}</view> -->
			<view class="myinfo_nickname">{{my_nickname}}</view>
		</view>
		
		<view class="tj_list">
			<!-- <view class="tjitem_list" > -->
			<view class="tjitem_list" @tap.stop="topage(99,'/pages/mypoints/mypoints')">
				<text class="tjil_txt1">{{my_points}}</text>
				<text class="tjil_txt2">我的积分</text>
			</view>
			<!-- <view class="tjitem_list"> -->
			<view class="tjitem_list" @tap.stop="topage(3,'/pages/mycoupon/mycoupon')">
				<text class="tjil_txt1">{{my_coupon}}</text>
				<text class="tjil_txt2">我的优惠</text>
			</view>
			<view class="tjitem_list" @tap.stop="topage(1,'/pages/myalbum/myalbum')">
				<text class="tjil_txt1">{{my_album}}</text>
				<text class="tjil_txt2">我的相册</text>
			</view>
		</view>
		<view class="my_serve">
			<view class="myserve_tit">我的服务</view>
			<view class="myserve_list">
				<view class="myservel_item" v-for="(item,index) in serves" :key="index"
					@tap.stop="topage(item.id,item.surl)">
					<uni-icons :type="item.sicon" size="30"></uni-icons>
					<text>{{item.name}}</text>
				</view>
			</view>
		</view>
		<view class="my_serve">
			<view class="myserve_tit">我的随想</view>
		</view>
		<view class="left">
			<view class="withbeat" @click="onShootDetail" v-for="item in leftlist" :key="item.id">
				<image :src="item.blogImgUrl" mode="aspectFill" class="cover" :style="{height:item.imageheight+'px'}"></image>
				<view class="beattext">{{item.blogTitle}}</view>
				<view class="details">
					<view class="user">
						<image :src="item.avatarUrl" mode="aspectFill"></image>
						<text class="name">{{item.nickname}}</text>
					</view>
					<view class="givealike">
						<uni-icons type="hand-up" size="25"></uni-icons>
						<text class="OfLikes">{{item.blogLikeNum}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="right">
			<view class="withbeat" @click="onShootDetail" v-for="item in rightlist" :key="item.id">
				<image :src="item.blogImgUrl" mode="aspectFill" class="cover" :style="{height:item.imageheight+'px'}"></image>
				<view class="beattext">{{item.blogTitle}}</view>
				<view class="details">
					<view class="user">
						<image :src="item.avatarUrl" mode="aspectFill"></image>
						<text class="name">{{item.nickname}}</text>
					</view>
					<view class="givealike">
						<uni-icons type="hand-up" size="25"></uni-icons>
						<text class="OfLikes">{{item.blogLikeNum}}</text>
					</view>
				</view>
			</view>
		</view>
		<!--弹出层 -->
		<uni-popup type="message" ref="WeChatCode" background-color="#fff">
			<view class="wcc_msg">
				<image src="http://zzqjt.oss-cn-hangzhou.aliyuncs.com/templates/client/res/ec489df8c9794ef0b1d53e40f80252ca-%E5%AE%A2%E6%9C%8D.jpg"></image>
			</view>
		</uni-popup>
		<Tabbar :page="page"></Tabbar>
	</view>
</template>
<script setup>
	import { ref,onMounted } from 'vue'
	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
	const baseUrl = getApp().globalData.baseUrl
	const blogurl = getApp().globalData.blogurl
	const title = ref('Hello')
	const windowheight=ref()
	const platform = ref()
	const statusBar = ref()
	const customBar = ref()
	const top = ref()
	const WeChatCode = ref(null)
	const my_points = ref(0)
	const my_coupon = ref(0)
	const my_album = ref(0)
	const my_nickname = ref()
	const my_avatarurl = ref()
	const client_no=ref()
	const leftlist=ref([])
	const rightlist=ref([])
	const Overalllist=ref([])
	const coverwidth=ref()
	const page=ref('/pages/my/my')
	const serves = [
		{
			id: 1,
			name: "我的相册",
			sicon: "images",
			surl: "/pages/myalbum/myalbum"
		},
		{
			id: 2,
			name: "我的订单",
			sicon: "calendar",
			surl: ""
		},
		{
			id: 3,
			name: "我的跟拍",
			sicon: "camera",
			surl: ""
		},
		{
			id: 4,
			name: "我的商拍",
			sicon: "navigate",
			surl: ""
		},
		{
			id: 5,
			name: "我的优惠",
			sicon: "map",
			surl: "/pages/mycoupon/mycoupon"
		},
		{
			id: 6,
			name: "开盲盒",
			sicon: "gift",
			surl: "/pages/blindbox/blindbox"
		},
		{
			id: 7,
			name: "每日签到",
			sicon: "compose",
			surl: "/pages/signin/signin"
		},
		{
			id: 8,
			name: "个人信息",
			sicon: "person",
			surl: "/pages/myinfo/myinfo"
		},
		{
			id: 9,
			name: "Ai笑客服号",
			sicon: "phone",
			surl: ""
		},
		
	]
	const getColumnHeight=()=>{
		uni.getSystemInfo({
			success(res) {
				//console.log(res)
				coverwidth.value=res.windowWidth*0.48-10
				platform.value = res.platform
				windowheight.value=res.screenHeight
				// #ifdef MP-WEIXIN
				statusBar.value = res.statusBarHeight
				const custom = wx.getMenuButtonBoundingClientRect()
				customBar.value = custom.bottom + custom.top - res.statusBarHeight
				// #endif
				// #ifdef APP-PLUS
				statusBar.value = res.statusBarHeight
				customBar.value = res.statusBarHeight + 45
				// 这里是在安卓手机上加上 3 像素（当时好像是在安卓水滴屏上，系统导航栏高度较低才加上去的，大家可以真机自己调试一下）
				if (res.platform == "android") {
					statusBar.value += 3
					customBar.value += 3
				}
				// #endif
			}
		})
		top.value = statusBar.value * 2 + (customBar.value - statusBar.value) * 2
		top.value=top.value/2
		windowheight.value=windowheight.value*2-top.value*2
		windowheight.value=windowheight.value/2-100
		//console.log(statusBar.value, customBar.value, top.value,windowheight.value)
	}

	onMounted(()=>{
		getColumnHeight()
	})
	onShow(()=>{
		const now = new Date().getTime()
		if (!uni.getStorageSync('token') || now > uni.getStorageSync('expireTime')) {
			uni.reLaunch({
				url: "/pages/login/login"
			})
		} else {
			getUserInfos()
			my_nickname.value = JSON.parse(uni.getStorageSync("user_info")).nickName
			my_avatarurl.value = JSON.parse(uni.getStorageSync("user_info")).avatarUrl
			client_no.value=JSON.parse(uni.getStorageSync("user_info")).client_no
			leftlist.value=[]
			rightlist.value=[]
			uni.request({
				url: blogurl + "/list",
				method: "POST",
				dataType: "json",
				header: {
					'content-type': 'application/json',
					'Access-Control-Allow-Origin': "*",
					'Authorization': uni.getStorageSync('token')
				},
				data: {},
				success: function(res) {
					//console.log(res)
					Overalllist.value=res.data.value
					for(let i=0;i<Overalllist.value.length;i++){
						uni.getImageInfo({
							src:Overalllist.value[i].blogImgUrl,
							success:function(image){
								//console.log(image)
								//console.log(image.height/image.width*coverwidth.value)
								Overalllist.value[i].imageheight=image.height/image.width*coverwidth.value
								//console.log(Overalllist.value)
							}
						})
						if(i%2===0){
							leftlist.value.push(Overalllist.value[i])
						}else{
							rightlist.value.push(Overalllist.value[i])
						}
					}
					//console.log(rightlist.value,leftlist.value)
				}
			})
		}
	})
	const tap=()=>{
		uni.navigateTo({
			url:"/pages/tap/tap"
		})
	}
	const topage = (id, surl) => {
		if (id == 9) {
			WeChatCode.value.open('center');
		} else {
			uni.navigateTo({
				url: surl
			})
		}
	
	}
	const getUserInfos = () => {
		uni.request({
			url: getApp().globalData.baseUrl + "/getinfo",
			method: "GET",
			header: {
				'content-type': 'application/json',
				'Access-Control-Allow-Origin': "*",
				'Authorization': uni.getStorageSync('token')
			},
			data: {
				openId: JSON.parse(uni.getStorageSync("user_info")).openId
			},
			success: (res) => {
				console.log(res,res.data.value.clientNickname )
				my_album.value = res.data.value.albumNum
				my_coupon.value = res.data.value.couponNum
				my_points.value = res.data.value.clientPoints
				my_nickname.value =res.data.value.clientNickname 
				my_avatarurl.value = res.data.value.clientAvatarUrl
				if(!res.data.value.clientNickname){
					my_nickname.value = JSON.parse(uni.getStorageSync("user_info")).nickName
				}
			},
			fail: (err) => {
				console.log(err)
			}
		})
	}
</script>
<style lang="less">
	.content {
		//display: flex;
		// flex-direction: column;
		flex-wrap: wrap;
		padding-bottom: 100px;
		background-color: #ffffff;
		//background-image: linear-gradient(to bottom,#d95e7d,#ffffff);
	}
	.myinfo {
		display: flex;
		background: url("http://zzqjt.oss-cn-hangzhou.aliyuncs.com/templates/client/res/b603ceb007cf42938e722d8cd2edbd8f-my-bg.png");
		background-size: 100%;
		background-origin: border-box;
		width: 100%;
		padding-top: 60rpx;
		height: 220rpx;
	}
	.myinfo_avator {
		width: 128rpx;
		height: 128rpx;
		border-radius: 50%;
		background-color: #fff;
		margin-left: 32rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.myinfo_avator image {
		width: 60%;
		height: 60%;
	}
	
	.myinfo_nickname {
		margin-left: 32rpx;
		font-size: 35rpx;
		font-weight: 600;
		line-height: 128rpx;
		color: #fff;
	}
	.tj_list {
		margin: -64rpx 64rpx 26rpx 64rpx;
		background-color: #fff;
		border-radius: 26rpx;
		height: 128rpx;
		display: flex;
		justify-content: space-evenly;
		//width: 100vw;
	}
	
	.tjitem_list {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 16rpx;
		line-height: 56rpx;
	}
	
	.tjil_txt1 {
		font-size: 32rpx;
		font-weight: 600;
	}
	
	.tjil_txt2 {
		font-size: 28rpx;
	}
	.my_serve {
		margin-top: 40rpx;
		width: 100vw;
	}
	
	.myserve_tit{
		padding-left: 32rpx;
		font-size: 32rpx;
		font-weight: bold;
		background-image: url("http://zzqjt.oss-cn-hangzhou.aliyuncs.com/templates/client/res/54a7fabeab254b7391ee9bf06fcf5598-line_bg.png");
		background-repeat: no-repeat;
		margin-left: 9rpx;
	}
	
	.myserve_list {
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		margin-top: 10rpx;
	
	}
	
	.myservel_item {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 24%;
		justify-content: space-between;
		margin: 20rpx 0;
		font-size: 28rpx;
	}
	
	.wcc_msg {
		height: 400rpx;
		background-color: #fff;
		width: 400rpx;
		padding: 20rpx;
	}
	
	.wcc_msg image {
		width: 100%;
		height: 100%;
	}
	.left {
		width: 48%;
		margin-left: 10rpx;
		float: left;
	}
	
	.right {
		width: 48%;
		margin-left: 10rpx;
		float: right;
	}
	
	.withbeat {
		padding: 10rpx;
		box-sizing: border-box;
		width: 100%;
		height: auto;
		background-color: #dddddd;
		border-radius: 30rpx;
		margin-top: 15rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	
		image {
			width: 100%;
			height: 500rpx;
			border-radius: 30rpx;
		}
	}
	
	
	.beattext {
		width: 90%;
		//height: 84rpx;
		overflow-wrap: break-word;
	}
	
	.details {
		width: 90%;
		height: 38rpx;
		vertical-align: middle;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.user{
			display: flex;
			align-items: center;
		}
	
		image {
			width: 38rpx;
			height: 38rpx;
			border-radius: 50%;
		}
	
		.name {
			margin-left: 10rpx;
			display: inline-block;
			font-size: 28rpx;
			height: 38rpx;
			line-height: 38rpx;
		}
	
		.OfLikes {
			display: inline-block;
			font-size: 28rpx;
			height: 38rpx;
			line-height: 38rpx;
		}
	}
</style>